<?php

use App\Api\AdminController;
use App\Api\CaptchaController;
use App\Api\LoginController;
use App\Api\PermissionController;
use App\Api\RoleController;
use App\Api\UploadController;
use Illuminate\Support\Facades\Route;


/**
 * =============系统服务==================
 */
//验证码
Route::get('captcha', [CaptchaController::class, 'create']);
//文件上传
Route::post('upload/local', [UploadController::class, 'local']);
//编辑器上传
Route::post('upload/wangeditor', [UploadController::class, 'wangEditor']);

Route::post('admin/login', [LoginController::class, 'login']);
//系统基础配置
Route::post('system/edit', [SystemController::class, 'store']);

/**
 * =============系统服务END==================
 */


Route::group(['prefix' => 'admin/', 'middleware' => ['auth:sanctum']], function () {

    /**
     * ==========后台管理员相关========
     */
    //用户列表
    Route::apiResource('admin', AdminController::class);
    //管理员信息
    Route::get('info', [AdminController::class, 'info']);

//单个管理员
    Route::get('admin/{admin}', [AdminController::class, 'show']);

//用户退出
    Route::post('logout', [AdminController::class, 'logout']);

//角色
    Route::Resource('role', RoleController::class);
//获取管理员所有角色
    Route::get('admin/{admin}/roles', [RoleController::class, 'hasRoles']);
//权限
    Route::get('permission', [PermissionController::class, 'edit']);
//管理员所有权限
    Route::get('permission/admin', [PermissionController::class, 'admin']);
//获取角色的权限数据
    Route::get('role/{role}/permissions', [RoleController::class, 'permissions']);
//为角色设置权限
    Route::put('role/{role}/permission', [PermissionController::class, 'update']);

//为管理员设置角色
    Route::put('admin/{admin}/role', [RoleController::class, 'syncRoles']);
    /**
     * ==========后台管理员相关END========
     */
});
